package com.sky.service;

import com.sky.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sky.entity.Admin;

@Service
public class AdminService {

    @Autowired
    private AdminMapper adminMapper;

    // 注册新管理员
    public Admin registerAdmin(String username, String password) {
        // 如果已存在同名管理员，返回 null
        if (adminMapper.existsByUsername(username)) {
            return null;
        }
        Admin admin = new Admin(username, password);
        // 插入数据库
        adminMapper.insertAdmin(admin);
        return admin;
    }

    // 登录示例（简单校验明文密码）
    public Admin loginAdmin(String username, String password) {
        Admin admin = adminMapper.selectByUsername(username);
        if (admin != null && admin.getPassword().equals(password)) {
            return admin; // 登录成功
        }
        return null; // 登录失败
    }
}